
const tokens = {
  'admin': {
    'test01': 'token-admin-test01'
  },
  'teacher': {
    'test01': 'token-teacher-test01'
  },
  'guard': {
    'test02': 'token-guard-test02'
  },
  'student': {
    'test01': 'token-student-test01'
  }
}

const users = {
  'token-admin-test01': {
    roles: ['admin'],
    introduction: '学校管理员',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'test01'
  },
  'token-teacher-test01': {
    roles: ['teacher'],
    introduction: '大学教师',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'test01'
  },
  'token-guard-test02': {
    roles: ['guard'],
    introduction: '门卫',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'test02'
  },
  'token-student-test01':{
    roles: ['student'],
    introduction: '在校大学生',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'test01'
  }
}

module.exports = [
  {
    url: '/vue-admin-template/user/login',
    type: 'post',
    response: config => {
      const { username, password, type } = config.body
      const token = tokens[type][username]

      if (!token) {
        return {
          code: 60204,
          message: '账号或密码错误'
        }
      }

      return {
        code: 20000,
        data: {
          'token': token
        }
      }
    }
  },

  {
    url: '/vue-admin-template/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  {
    url: '/vue-admin-template/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
